{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    <h3 class="pb-3">添加信息</h3>
    {if condition="($id == 0)"}
    <table class="layui-table layui-table-form">
        <tr >
            <td colspan="6"><strong>资质信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">资质类别</td>
            <td id="cert_type">
                <!--<input type="text" name="cert_type" lay-reqText="资质类别"-->
                                      <!--autocomplete="off" placeholder="资质类别" class="layui-input">-->
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">资质名称</td>
            <td id="cert_name">
                <!--<input type="text" name="cert_name" lay-reqText="资质名称"-->
                       <!--autocomplete="off" placeholder="请输入资质名称" class="layui-input">-->
            </td>
            <td class="layui-td-gray">登记日期</td>
            <td>
                <input type="text" name="register_time" id="register_time" autocomplete="off"
                       lay-reqText="登记日期" placeholder="登记日期" class="layui-input">
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>购买方信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">购买方企业</td>
            <td>
                <input type="text" name="buy_company" autocomplete="off"
                       lay-reqText="购买方企业" placeholder="购买方企业" class="layui-input">
                <input type="text"  value="查找企业"
                       class="layui-input  license-picker1" style="width: 80px;margin-top: 10px;">
            </td>
            <td class="layui-td-gray">购买方联系人</td>
            <td>
                <input type="text" name="buy_name" autocomplete="off"
                       lay-reqText="购买方联系人" placeholder="购买方联系人" class="layui-input">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">购买方联系电话</td>
            <td>
                <input type="text" name="buy_phone" value="" autocomplete="off" placeholder="购买方联系人"
                       lay-reqText="购买方联系人" class="layui-input">
            </td>
            <td class="layui-td-gray">购买方金额</td>
            <td>
                <input type="text" name="buy_money" value="" autocomplete="off"
                       lay-reqText="购买方金额" placeholder="购买方金额" class="layui-input">
            </td>
        </tr>

        <tr>
            <td colspan="6"><strong>转让方信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">转让方企业</td>
            <td>
                <input type="text" name="transfer_company" autocomplete="off" placeholder="请选择或者输入"
                       class="layui-input">
                <input type="text"  value="查找企业"
                       class="layui-input  license-picker" style="width: 80px;margin-top: 10px;">
            </td>
            <td class="layui-td-gray">转让方联系人</td>
            <td>
                <input type="text" name="transfer_name" autocomplete="off"
                       lay-reqText="转让方联系人" placeholder="转让方联系人" class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">转让方联系电话</td>
            <td>
                <input type="text" name="transfer_phone" value="" autocomplete="off" placeholder="转让方联系电话"
                       lay-reqText="转让方联系电话" class="layui-input">
            </td>
            <td class="layui-td-gray">转让方金额</td>
            <td>
                <input type="text" name="transfer_money" value="" autocomplete="off"
                       lay-reqText="转让方金额" placeholder="转让方金额" class="layui-input">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">利润</td>
            <td>
                <input type="number" name="profit" value="" autocomplete="off" placeholder="利润"
                       lay-verify="required" lay-reqText="利润" class="layui-input">
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>签单信息</strong></td>
        </tr>
        <tr id="flow_tr">
            <td class="layui-td-gray">签单人</td>
            <td>
                <input type="text" name="sign_name" autocomplete="off"
                       lay-reqText="请选择签单人" lay-verify="required" placeholder="请选择签单人" class="layui-input picker-one"
                       readonly>
                <input type="hidden" name="sign_id" readonly>
            </td>
        </tr>
        <!--<tr>-->
            <!--<td class="layui-td-gray">提成金额</td>-->
            <!--<td>-->
                <!--<input type="number" name="deduct" autocomplete="off"-->
                       <!--lay-reqText="提成金额" placeholder="提成金额" class="layui-input">-->
            <!--</td>-->
        <!--</tr>-->

        <tr>
            <td colspan="6"><strong>附件上传</strong></td>
        </tr>
        <tr>
            <td colspan="6"><strong>请将附件名称描述清楚</strong></td>
        </tr>

        <tr>
            <td class="layui-td-gray">
                <button type="button" class="layui-btn layui-btn-sm" id="uploadBtn"><i class="layui-icon"></i>附件上传
                </button>
            </td>
            <td colspan="5" style="line-height:inherit">
                <div class="layui-row" id="fileBox">
                    <input type="hidden" id="fileBoxInput" data-type="file" name="file_ids" value="">
                </div>
            </td>
        </tr>

        <tr>
            <td colspan="6">
                <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea"></textarea>
            </td>
        </tr>
    </table>
    {else/}
    <table class="layui-table layui-table-form">
        <tr>
            <td colspan="6"><strong>资质信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">资质类别</td>
            <td> <input type="text" name="cert_type" lay-reqText="资质类别"
                        autocomplete="off" placeholder="资质类别" value="{$detail.cert_type}" class="layui-input"></td>
        </tr>
        <tr>
            <td class="layui-td-gray">资质名称</td>
            <td>
                <input type="text" name="cert_name" value="{$detail.cert_name}" lay-reqText="资质名称"
                       autocomplete="off" placeholder="请输入资质名称" class="layui-input">
            </td>
            <td class="layui-td-gray">登记日期</td>
            <td>
                <input type="text" name="register_time" id="register_time" value="{$detail.register_time}"
                       autocomplete="off"
                       lay-reqText="登记日期" placeholder="登记日期" class="layui-input">
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>购买方信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">购买方企业</td>
            <td>
                <input type="text" name="buy_company" value="{$detail.buy_company}" autocomplete="off"
                       lay-reqText="购买方企业" placeholder="购买方企业" class="layui-input">
                <input type="text"  value="查找企业"
                       class="layui-input  license-picker1" style="width: 80px;margin-top: 10px;">
            </td>
            <td class="layui-td-gray">购买方联系人</td>
            <td>
                <input type="text" name="buy_name" value="{$detail.buy_name}" autocomplete="off"
                       lay-reqText="购买方联系人" placeholder="购买方联系人" class="layui-input">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">购买方联系电话</td>
            <td>
                <input type="text" name="buy_phone" value="{$detail.buy_phone}" autocomplete="off" placeholder="购买方联系人"
                       lay-reqText="购买方联系人" class="layui-input">
            </td>
            <td class="layui-td-gray">购买方金额</td>
            <td>
                <input type="text" name="buy_money" value="{$detail.buy_money}" autocomplete="off"
                       lay-reqText="购买方金额" placeholder="购买方金额" class="layui-input">
            </td>
        </tr>

        <tr>
            <td colspan="6"><strong>转让方信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray">转让方企业</td>
            <td>
                <input type="text" name="transfer_company" value="{$detail.transfer_company}" autocomplete="off"
                       lay-reqText="转让方企业" placeholder="转让方企业" class="layui-input">
                <input type="text"  value="查找企业"
                       class="layui-input  license-picker" style="width: 80px;margin-top: 10px;">
            </td>
            <td class="layui-td-gray">转让方联系人</td>
            <td>
                <input type="text" name="transfer_name" value="{$detail.transfer_name}" autocomplete="off"
                       lay-reqText="转让方联系人" placeholder="转让方联系人" class="layui-input">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">转让方联系电话</td>
            <td>
                <input type="text" name="transfer_phone" value="{$detail.transfer_phone}" autocomplete="off"
                       placeholder="转让方联系电话"
                       lay-reqText="转让方联系电话" class="layui-input">
            </td>
            <td class="layui-td-gray">转让方金额</td>
            <td>
                <input type="text" name="transfer_money" value="{$detail.transfer_money}" autocomplete="off"
                       lay-reqText="转让方金额" placeholder="转让方金额" class="layui-input">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">利润</td>
            <td>
                <input type="number" name="profit" value="{$detail.profit}" autocomplete="off" placeholder="利润"
                       lay-verify="required" lay-reqText="利润" class="layui-input">
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>签单信息</strong></td>
        </tr>
        <tr id="flow_tr">
            <td class="layui-td-gray">签单人</td>
            <td>
                <input type="text" name="sign_name" value="{$detail.sign_name}" autocomplete="off"
                       lay-reqText="请选择签单人" lay-verify="required" placeholder="请选择签单人" class="layui-input picker-one"
                       readonly>
                <input type="hidden" name="sign_id" value="{$detail.sign_id}" readonly>
            </td>
        </tr>
        <!--<tr>-->
            <!--<td class="layui-td-gray">提成金额</td>-->
            <!--<td>-->
                <!--<input type="number" name="deduct" value="{$detail.deduct}" autocomplete="off"-->
                       <!--lay-reqText="提成金额" placeholder="提成金额" class="layui-input">-->
            <!--</td>-->
        <!--</tr>-->

        <tr>
            <td colspan="6"><strong>附件上传</strong></td>
        </tr>
        <tr>
            <td colspan="6"><strong>请将附件名称描述清楚</strong></td>
        </tr>

        <tr>
            <td class="layui-td-gray">
                <button type="button" class="layui-btn layui-btn-sm" id="uploadBtn"><i class="layui-icon"></i>附件上传
                </button>
            </td>
            <td colspan="5" style="line-height:inherit">
                <div class="layui-row" id="fileBox">
                    <input type="hidden" data-type="file" name="file_ids" value="{$detail.file_ids}">
                    {notempty name="$detail.file_ids"}
                    {volist name="$detail.fileArray" id="vo"}
                    <div class="layui-col-md4" id="uploadImg{$vo.id}">{:file_card($vo)}</div>
                    {/volist}
                    {/notempty}
                </div>
            </td>
        </tr>

        <tr>
            <td colspan="6">
                <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea">{$detail.remark}</textarea>
            </td>
        </tr>
    </table>
    {/if}

    <div class="py-3">
        <input name="id" id="id" type="hidden" value="{$id}">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool', 'employeepicker', 'oaTool'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool, table = layui.table, laydate = layui.laydate, oaTool = layui.oaTool,
            employeepicker = layui.employeepicker;

        //相关附件上传
        oaTool.addFile();

        laydate.render({
            elem: '#register_time',
            showBottom: false
        });
        laydate.render({
            elem: '#return_account_date',
            showBottom: false
        });
        laydate.render({
            elem: '#remit_account_date',
            showBottom: false
        });

        //radio选择
        form.on('radio(tax)', function (data) {
            if (data.value == 0) {
                $('[name="tax"]').val('0').hide();
            } else {
                $('[name="tax"]').val('').show();
            }
        });

        //监听提交
        form.on('submit(webform)', function (data) {

            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/busine/businetransfer/add", data.field, callback);
            return false;
        });

        //选择关联的公司
        $('.license-picker').on('click', function () {
            let that = $(this);
            let callback = function(data){
                $('[name="transfer_company"]').val(data.company_name);

                tool.post("/license/api/cert_index", {'company_name':data.company_name}, function (e) {
                    if (e.code == 0) {
                        $("#cert_name").html(e.data.projects+'<input type="hidden" name="cert_name" value="'+e.data.projects+'">');
                        $("#cert_type").html(e.data.cert_type+'<input type="hidden" name="cert_type" value="'+e.data.cert_type+'">');
                        layer.close(index);
                    }
                });
                return false;
            }
            oaTool.outsidPicker(callback);
        });




        //选择关联的公司
        $('.license-picker1').on('click', function () {
            let that = $(this);
            let callback = function(data){
                $('[name="buy_company"]').val(data.company_name);
            }
            oaTool.outsidPicker(callback);
        });

        form.on('select(flowtype)', function (data) {
            var check_type = data.elem[data.elem.selectedIndex].title;
            var formHtml = '<td class="layui-td-gray">审核人<font>*</font></td>\
		<td colspan="5">\
			<input type="text" name="sign_name" value="" autocomplete="off" placeholder="请选择签约人" lay-verify="required" lay-reqText="请选择签约人" class="layui-input picker-one"><input type="hidden" name="sign_id" value="">\
		</td>';
            if (check_type == 2) {
                $('#flow_tr').html(formHtml);
                form.render();
            }
            if (data.value == '') {
                $('#flow_tr').html(formHtml);
                $('[name="copy_names"]').val('');
                $('[name="copy_uids"]').val('');
                form.render();
                return false;
            }
            $.ajax({
                url: "/api/index/get_flow_users",
                type: 'get',
                data: {id: data.value},
                success: function (e) {
                    if (e.code == 0) {
                        var flowLi = '';
                        var flow_data = e.data.flow_data;
                        if (e.data.copy_uids && e.data.copy_uids != '') {
                            $('[name="copy_names"]').val(e.data.copy_unames);
                            $('[name="copy_uids"]').val(e.data.copy_uids.split(','));
                        }
                        if (check_type == 1 || check_type == 3) {
                            for (var a = 0; a < flow_data.length; a++) {
                                var userList = '', sign_type = '';
                                if (check_type == 1) {
                                    if (flow_data[a].flow_type == 1) {
                                        userList += '<li style="padding:3px 0">当前部门负责人</li>';
                                    }
                                    else if (flow_data[a].flow_type == 2) {
                                        userList += '<li style="padding:3px 0">上级部门负责人</li>';
                                    }
                                    else {
                                        if (flow_data[a].flow_type == 3) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">或签</span>';
                                        }
                                        if (flow_data[a].flow_type == 4) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">会签</span>';
                                        }
                                        for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                            userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                        }
                                    }
                                }
                                else if (check_type == 3) {
                                    sign_type = ' <span class="layui-badge layui-bg-blue">' + flow_data[a].flow_name + '</span>'
                                    for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                        userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                    }
                                }
                                flowLi += '<li class="layui-timeline-item">\
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
								<div class="layui-timeline-content">\
								  <p class="layui-timeline-title"><strong>第' + (a + 1) + '级审批</strong>' + sign_type + '</p>\
								  <ul>' + userList + '</ul>\
								</div>\
							</li>';
                            }
                            formHtml = '<td class="layui-td-gray">审批流程</td>\
									<td colspan="7">\
										<ul id="flowList" class="layui-timeline">' + flowLi + '</ul>\
									</td>';
                            $('#flow_tr').html(formHtml);
                        }
                    }
                }
            })
        });
    }
</script>
{/block}
<!-- /脚本 -->